<!-- zTree -->
<SCRIPT type='text/javascript' src="${base}/js/ztree/js/jquery.ztree.core-3.4.min.js"></SCRIPT>
<SCRIPT type='text/javascript' src="${base}/js/ztree/js/jquery.ztree.excheck-3.4.min.js"></SCRIPT>
<link rel="stylesheet" type="text/css" href="${base}/js/ztree/css/zTreeStyle/zTreeStyle.css">
<!-- dwr -->
<script type='text/javascript' src='${base}/dwr/engine.js'></script>
<script type='text/javascript' src='${base}/dwr/util.js'></script>
<script type='text/javascript' src='${base}/dwr/interface/backRoleService.js'></script>

<script type="text/javascript">
	j(function(){
		j.fn.zTree.init(j("#ztreeul"), setting, zNodes);
		j("#expandAllBtn").bind("click", {type:"expandAll"}, expandNode);
		j("#collapseAllBtn").bind("click", {type:"collapseAll"}, expandNode);
	})
		var setting = {
			data: {
				simpleData: {
					enable: true,
					idKey: "id",
					pIdKey: "pId",
					rootPId: 0
				}
			},
			check: {
				enable: true,
				chkboxType: { "Y" : "ps", "N" : "ps" }
			}
		};
	var zNodes =[
	    <#if bpLevelIs?exists && bpLevelIs?size gt 0>
	    	<#list bpLevelIs as bpLevelI>
	    		{ id:${bpLevelI.id?if_exists},pId:${bpLevelI.parent?default(0)},pLevel:"${bpLevelI.level?if_exists}",name:"${bpLevelI.name} (No.${bpLevelI.sortNo?if_exists?c})",open:true,isParent:true,icon:"${base}/images/3.gif"<#if bpLevelI.isSelect?exists && bpLevelI.isSelect = 1>,checked:true</#if>}<#if bpLevelI_has_next>,<#else><#if bpLevelIIs?exists && bpLevelIIs?size gt 0>,</#if></#if>
	    	</#list>
			
	    	<#list bpLevelIIs as bpLevelII>
	    		{ id:${bpLevelII.id?if_exists},pId:${bpLevelII.parent.id?default(0)},pLevel:"${bpLevelII.level?if_exists}",name:"${bpLevelII.name} (No.${bpLevelII.sortNo?if_exists?c})",open:true,icon:"${base}/images/11.gif"<#if bpLevelII.isSelect?exists && bpLevelII.isSelect = 1>,checked:true</#if>}<#if bpLevelII_has_next>,</#if>
	    	</#list>
		</#if>
	];
	
	function submitForm(){
		if(!checkForm()){
			return;
		}
		
		var zTree = j.fn.zTree.getZTreeObj("ztreeul");
		
		var nodes=zTree.getCheckedNodes(true);
		
		var purviewStr="";
		j.each(nodes,function(i,node){
			purviewStr+=node.id+","
		})
		if(purviewStr.length >0){
			purviewStr=purviewStr.substring(0,purviewStr.length-1);
		}

		dwr.engine.setAsync(false);
		var callBack=function(data){
			parent.addSuccess("backRoleManage.action");
			closerparent();
		}
		var BackRole={
				"id":"<#if role?exists>${role.id?if_exists}</#if>",
				"name":j.trim(j("#Rname").val()),
				"remark":j.trim(j("#Rremark").val())
		}
		backRoleService.saveBackRoleDWR(BackRole,purviewStr,callBack)
		dwr.engine.setAsync(true);
	}
	
	function checkForm(){
		if(j.trim(j("#Rname").val()).length == 0){
			alert("角色名称不能为空")
			return false;
		}

		return true;
	}
	
	function closerparent(){
	    parent.floatboxclose(false);
	}
	
	function expandNode(e) {
		var zTree = j.fn.zTree.getZTreeObj("ztreeul"),
		type = e.data.type,
		nodes = zTree.getSelectedNodes();
		if (type.indexOf("All")<0 && nodes.length == 0) {
			alert("请先选择一个父节点");
		}

		if (type == "expandAll") {
			zTree.expandAll(true);
		} else if (type == "collapseAll") {
			zTree.expandAll(false);
		} else {
			var callbackFlag = $("#callbackTrigger").attr("checked");
			for (var i=0, l=nodes.length; i<l; i++) {
				zTree.setting.view.fontCss = {};
				if (type == "expand") {
					zTree.expandNode(nodes[i], true, null, null, callbackFlag);
				} else if (type == "collapse") {
					zTree.expandNode(nodes[i], false, null, null, callbackFlag);
				} else if (type == "toggle") {
					zTree.expandNode(nodes[i], null, null, null, callbackFlag);
				} else if (type == "expandSon") {
					zTree.expandNode(nodes[i], true, true, null, callbackFlag);
				} else if (type == "collapseSon") {
					zTree.expandNode(nodes[i], false, true, null, callbackFlag);
				}
			}
		}
	}
	
	function checkAllNodes(flag){
		var zTree = j.fn.zTree.getZTreeObj("ztreeul");
		zTree.checkAllNodes(flag);
	}
</script>

<div>
<div class="close"></div>
<div class="itemtitle"><h3>${control?if_exists}角色<span id="post-form-loading"></span></h3></div>
<form >
<input type="button" value="全部展开" id="expandAllBtn"/>&nbsp;<input type="button" value="全部收缩" id="collapseAllBtn"/>&nbsp;
<input type="button" value="全选" onclick="checkAllNodes(true)">&nbsp;<input type="button" value="全不选" onclick="checkAllNodes(false)">
	<div>
		<ul id="ztreeul" class="ztree"></ul>
	</div>
<table border="0" class="tb tb2" >
	<tr>
		<td class=td21>角色名称：</td>
		<td ><input id="Rname" <#if role?exists>value="${role.name?if_exists}"</#if> /></td>
	</tr>
	<tr>
		<td class=td21>备注：</td>
		<td id="storeNo"><input id="Rremark" <#if role?exists>value="${role.remark?if_exists}"</#if> /></td>
	</tr>
	<tr>
		<td colspan="2">
			<img src="${base}/images/button/baocun.gif" onclick ="submitForm()" style="cursor: pointer;"/>&nbsp;&nbsp;
			<img src="${base}/images/button/quxiao.gif" onclick ="closerparent()" style="cursor: pointer;"/>
		</td>
	</tr>
</table>
</form>



</div>